package thread;

/**
 * Date: 2025-04-2025/4/30
 * User: 11
 * Time: 10:26
 */
//创建线程的第一种写法
//创建一个类,继承自 Thread
    class MyThread extends Thread {
    @Override
    public void run() {
        //线程的入口方法
        while(true) {
            System.out.println("hello thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new MyThread();//向上转型.
        //启动线程
        t.start();
        while(true) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
